package com.edu.d10_test;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

/**
 * 几位同学去各个旅游景点，统计景点去的最多的人数
 */
public class Test1 {
    public static void main(String[] args) {

        //存储，一个同学对应多个景点地方
        Map<String, List<String>> hashMap = new HashMap<>();
        List<String> list1 = new ArrayList<>();
        Collections.addAll(list1,"农家乐","野外拓展");
        hashMap.put("张全蛋儿",list1);

        List<String> list2 = new ArrayList<>();
        Collections.addAll(list2,"轰趴","野外拓展","健身房");
        hashMap.put("李二狗子",list2);

        List<String> list3 = new ArrayList<>();
        Collections.addAll(list3,"野外拓展");
        hashMap.put("翠花",list3);

        List<String> list4 = new ArrayList<>();
        Collections.addAll(list4,"轰趴","健身房");
        hashMap.put("小帅",list4);

        List<String> list5 = new ArrayList<>();
        Collections.addAll(list5,"农家乐");
        hashMap.put("有容",list5);

        //用于记录地点和人数
        Map<String, Integer> map = new HashMap<>();
        hashMap.forEach(new BiConsumer<String, List<String>>() {
            @Override
            public void accept(String s, List<String> strings) {
                for (String string : strings) {
                    map.put(string,map.containsKey(string)?map.get(string)+1:1);
                }
            }
        });

        System.out.println(map);
        Map.Entry<String,Integer> entity=map.entrySet().stream().max(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return o1.getValue()- o2.getValue();
            }
        }).get();
        List<String> collect = map.entrySet().stream().filter(e -> e.getValue() == entity.getValue()).map(e -> e.getKey()).collect(Collectors.toList());
        System.out.println(collect);

        hashMap.entrySet().stream().filter(e->{
            boolean flag=true;   //没有包含
            for (String s : e.getValue()) {
                if(collect.contains(s)){
                    flag=false;
                    break;
                }
            }
            return flag;
        }).forEach(e-> System.out.println(e.getKey()));
    }
}
